<template>
  <view>
    <uni-list v-if="userinfo">
      <uni-list-item title="头像">
        <template v-slot:footer>
          <image class="nick"
                 :src="userinfo.head"
                 mode="widthFix"
                 @click="chooseHead"></image>
        </template>
      </uni-list-item>
      <uni-list-item title="昵称"
                     clickable
                     :rightText="userinfo.nickname"
                     @click="userEdit('nick')" />
      <uni-list-item title="电话"
                     clickable
                     :rightText="userinfo.phone"
                     @click="userEdit('phone')" />
      <uni-list-item title="认证"
                     clickable
                     :rightText="userinfo.phone"
                     @click="userEdit('phone')" />
    </uni-list>
  </view>
</template>
<script>

import config from "@/common/config.js"
export default {
  data () {
    return {
      userinfo: {}
    }
  },
  onShow () {
    this.userinfo = this.$store.state.user_info
  },
  methods: {
    userEdit (e) {
      this.$Router.push({
        path: '/pages/user_edit/user_edit',
        query: {
          type: e,
        },
      })
    },
    chooseHead () {
      let that = this
      var token = uni.getStorageSync('token')
      uni.chooseImage({
        // count:  允许上传的照片数量
        count: 1,
        // sizeType:  original 原图，compressed 压缩图，默认二者都有
        sizeType: "original",
        success (res) {
          uni.uploadFile({
            url: config.baseUrl + 'mine/head_upload',
            filePath: res.tempFilePaths[0],
            name: 'file',
            header: {
              Authorization: `Bearer ${token}`,
            },
            success: (uploadFileRes) => {
              let imgValue = JSON.parse(uploadFileRes.data)
              that.userinfo.head = imgValue.data.path
              this.$store.commit('setUserInfo', that.userinfo)
            }
          });
        }
      });
    },
  }

}
</script>
<style>
.uni-list-item__container {
  align-items: center;
}
</style>
<style lang="scss">
.nick {
  width: 80upx;
  height: 80upx;
}
</style>